﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Handsfree
{
    public partial class List : Form
    {
        private ListViewColumnSorter lvwColumnSorter;
        public List()
        {
            InitializeComponent();
            LoadCommands();
            lvwColumnSorter = new ListViewColumnSorter();
            this.listView1.ListViewItemSorter = lvwColumnSorter;
        }
        public void LoadCommands()
        {
            listView1.View = System.Windows.Forms.View.Details;
            /*listView1.Columns.Add("Type");
            listView1.Columns.Add("Speech Command");
            listView1.Columns.Add("Action");*/
            SpeechRecognition s = new SpeechRecognition(false);
            List<Command> list = s.returnCommands();
            foreach (Command c in list)
            {
                String[] str =  {c.type, c.speech, c.action };
                ListViewItem lvi = new ListViewItem(str);
                listView1.Items.Add(lvi);
            }
        }

        private void listView1_ColumnClick(object sender, ColumnClickEventArgs e)
        {


            // Determine if clicked column is already the column that is being sorted.
            if (e.Column == lvwColumnSorter.SortColumn)
            {
                // Reverse the current sort direction for this column.
                if (lvwColumnSorter.Order == SortOrder.Ascending)
                {
                    lvwColumnSorter.Order = SortOrder.Descending;
                }
                else
                {
                    lvwColumnSorter.Order = SortOrder.Ascending;
                }
            }
            else
            {
                // Set the column number that is to be sorted; default to ascending.
                lvwColumnSorter.SortColumn = e.Column;
                lvwColumnSorter.Order = SortOrder.Ascending;
            }

            // Perform the sort with these new sort options.
            this.listView1.Sort();				
        }

    }
}
